package com.hontech.libratest.activity.fragment.sub

import android.view.View
import android.widget.Button
import com.hontech.libratest.R
import com.hontech.libratest.activity.window.showProg
import com.hontech.libratest.conn.pickDoorClose
import com.hontech.libratest.conn.pickDoorOpen
import com.hontech.libratest.utils.onClick


class PickDoorSub(view: View) {

    private val btnOpen = view.findViewById<Button>(R.id.id_main_btn_pick_open)
    private val btnClose = view.findViewById<Button>(R.id.id_main_btn_pick_close)

    init {
        btnOpen.onClick(::onClickOpen)
        btnClose.onClick(::onClickClose)


    }

    private suspend fun onClickOpen() {
        val w = showProg(btnOpen, "打开取物门")
        try {
            pickDoorOpen()
            w.success("打开取物门成功")
        } catch (e: Exception) {
            e.printStackTrace()
            w.error(e.message!!)
        }
    }

    private suspend fun onClickClose() {
        val w = showProg(btnOpen, "关闭取物门")
        try {
            pickDoorClose()
            w.success("关闭取物门成功")
        } catch (e: Exception) {
            e.printStackTrace()
            w.error(e.message!!)
        }
    }
}